class QueriesController < ApplicationController
  def create
    user = User.find(:first, :conditions => ["email = ? or mobile_no = ?", params[:user][:email].strip.downcase, params[:user][:mobile_no].strip.downcase])
    user = User.create(params[:user]) if user.nil?
    
    advertisment        = Advertisment.find(params[:advertisment_id])
    query               = Query.create(params[:query])
    query.user          = user
    query.advertisment  = advertisment
    query.save

    attachment = Attachment.create
    attachment.file = params[:attachment][:file]
    
    attachment.query_id = query.id
    attachment.save

    redirect_to :controller => "advertisments", :action => "show", :id => advertisment
  end
end
